// 获取年月日时分秒
const formatTimeYMDHMS = (date) => {
  console.log(date)
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var date = date.getDate();
  year = year.toString().slice(2);
  month = month > 9 ? month : "0" + month;
  date = date > 9 ? date : "0" + date;
  hours = hours > 9 ? hours : "0" + hours;
  minutes = minutes > 9 ? minutes : "0" + minutes;
  return year + "年" + month + "月" + date + "日 " + hours + ":" + minutes;
}

// 获取年月日
const formatTimeYMD = (date)=>{
  console.log(date)
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var date = date.getDate();
  month = month > 9 ? month : "0" + month; 
  date = date > 9 ? date : "0" + date; 
  return year + "-" + month  + "-" + date;
}

// 获取时分秒数组
const formatTimeHMS = (date) => {
  console.log(date)
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var seconds = date.getSeconds();
  return [formatTimeStyle(hours), formatTimeStyle(minutes), formatTimeStyle(seconds)];
}

const formatTimeStyle = (val)=>{
  val = val > 9 ? val : "0"+val;
  return val;
}

module.exports = {
  formatTimeYMDHMS: formatTimeYMDHMS,
  formatTimeYMD: formatTimeYMD,
  formatTimeHMS: formatTimeHMS
}

